// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/firecontrol/api/XfDevicePointApi'

import ComClass from '@api/ComQuery'

import ListClass from '@api/firecontrol/model/QueryXfDevicePointListReq'
import EditClass from '@api/firecontrol/model/UpdateXfDevicePointReq'
import BaseClass from '@api/firecontrol/model/XfDevicePointDto'
import DownloadClass from '@api/firecontrol/model/XfDevicePointTemplateDownLoadReq'
import UploadClass from '@api/firecontrol/model/XfDevicePointExcelImportReq'
import UpProgressClass from '@api/firecontrol/model/XfDevicePointExcelImportProcessReq'

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']
const BASE = [BaseClass, 'content']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  async getList(param, TIP = '查询列表') {
    const DTO = CORE.grpcDTO(ListClass, param, COM)
    const resp = await CORE.grpc(TIP, CLIENT, 'queryXfDevicePointList', DTO)
    return [resp.comQuery.totalCount, resp.content || [], resp.statusCountDto || {}]
  },
  transList(arr) {
    arr.forEach((item) => {
      item.oldAreaId = item.areaId
      item.videoDto = { id: item.cameraId, deviceName: item.cameraName }
    })
    return arr
  },

  // —————————————————————————————— 修改 —————————————————————————————— //

  async edit(one, TIP = '修改') {
    const DTO = CORE.grpcDTO(EditClass, one, BASE)
    await CORE.grpc(TIP, CLIENT, 'updateXfDevicePoint', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 下载 —————————————————————————————— //

  async download(downParam, TIP = '下载模板') {
    const DTO = CORE.grpcDTO(DownloadClass, downParam)
    await CORE.grpcDownload(TIP, CLIENT, 'xfDevicePointTemplateDownLoad', DTO, null, '消防导入模板.xlsx')
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 上传 —————————————————————————————— //

  async upload(upParam, TIP = '上传文件') {
    const DTO = CORE.grpcDTO(UploadClass, upParam)
    const resp = await CORE.grpc(TIP, CLIENT, 'xfDevicePointExcelImport', DTO)
    return resp.taskId
  },

  // —————————————————————————————— 上传进度 —————————————————————————————— //

  async upProgress(upProgress, TIP = '查询上传进度') {
    const DTO = CORE.grpcDTO(UpProgressClass, upProgress)
    const resp = await CORE.grpc(TIP, CLIENT, 'xfDevicePointExcelImportProcess', DTO)
    return resp
  },
}
